# coding=utf-8
"""
author: jamon
"""
from __future__ import annotations

import os

import pygame

from client.config import ClientConfig
from client.model.gate_data import GateData
from package.posi import Position
from package.static.const import TypeIdConst
from package.universe import universe
from pygame import Rect, Surface
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from client.views.battle_scene import BattleScreen
    from client.model.tank.tank_base import TankBase


class Skill(pygame.sprite.Sprite):

    def __init__(self, type_id: TypeIdConst, **kwargs):
        super(Skill, self).__init__()
        base_info = universe.get_skill_info(type_id)
        self.type_id = type_id
        self.name: str = base_info.name
        root_dir = ClientConfig().root_dir
        self.image: Surface = pygame.image.load(os.path.join(root_dir, base_info.image))
        self.rect: Rect = self.image.get_rect()

        self.life = base_info.life * GateData().frame_physical_rate

    def init_position(self, position: Position):
        self.rect.left, self.rect.top = position.x, position.y

    def tick_by_per_frame(self):
        self.life -= 1

    def can_remove(self) -> bool:
        return 0 >= self.life

    def pick(self, screen: BattleScreen, tank: TankBase) -> None:
        # 技能书被拾取时，自动触发技能
        if TypeIdConst.SKILL_WEAPON_UPGRADE_C == self.type_id:
            # 武器升级到C级
            tank.upgrade(TypeIdConst.TANK_LEVEL_2_1)
        elif TypeIdConst.SKILL_WEAPON_UPGRADE_B == self.type_id:
            # 武器升级到C级
            tank.upgrade(TypeIdConst.TANK_LEVEL_3_1)
